package gof23.behavior.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 信号灯(作为被观察者)
 */
public class SignalLight implements Subject{
	
	private List<Observer> list = new ArrayList<Observer>();
	
	private String message;

	@Override
	public void registerObserver(Observer observer) {
		list.add(observer);
		
	}

	@Override
	public void removeObserver(Observer observer) {
		list.remove(observer);
		
	}

	@Override
	public void notifyObserver() {
		list.forEach(e->{e.update(message);});
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
		notifyObserver();
	}
	
	

}
